package com.siki.config.mybatisConfig;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.siki.pojo.enumeration.common.UserRole;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Mybatis字段初始化配置类
 *
 * @Author Siki
 * @Date 2020/6/5
 */
@Component
@EnableTransactionManagement
@MapperScan("com.siki.mapper")
public class MybatisFillConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("version", 1,metaObject);
        this.setFieldValByName("deleted", 0,metaObject);
        this.setFieldValByName("forbid",false,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
    }
}
